/*
 * 产品搜索
 * @Author: ljb
 * @Date: 2018-03-27 17:51:07
 * @Last Modified by: kanglin
 * @Last Modified time: 2018-06-05 11:44:08
 */
<template>
	<Form
		ref="formInline"
		:model="formValidate"
		:label-width="150">

		<Form-item
			:label="$t('product.please_select_status')"
			porp="brand_id">
			<Select
				v-model="formValidate.type"
				clearable
				style="width:120px">
				<Option
					v-for="status in status_options"
					:value="status.value"
					:key="status.value">{{ status.label }}</Option>
			</Select>
		</Form-item>

		<Form-item
			v-if="formValidate.type"
			:label="$t('product.is_open')"
			prop="has_hair">
			<i-switch
				v-model="formValidate.value"
				true-value="1"
				false-value="0">
				<Icon
					slot="open"
					type="android-done"/>
				<Icon
					slot="close"
					type="android-close"/>
			</i-switch>
		</Form-item>

		<Form-item>
			<Button
				type="primary"
				@click="confirmUpdate">
				{{ $t('common.confirm_update') }}
			</Button>
		</Form-item>

	</Form>
</template>
<script>

export default {

	name: 'ProductStatusEdit',

	props: {

		detail: {
			type: Object,
			default() {
				return {};
			},
		},

	},

	data() {
		return {
			status_options: [
				{
					label: this.$t('product.sold_state'),
					value: 'is_sale',
				},
				{
					label: this.$t('product.hot_state'),
					value: 'is_hot',
				},
				{
					label: this.$t('product.new_product_state'),
					value: 'is_new',
				},
				{
					label: this.$t('product.up_down'),
					value: 'is_deleted',
				},
			],
			formValidate: {
				type: '',

				value: '0',
			}, // 搜索框的对象参数
		};
	},
	watch: {

		'formValidate.type': function changeValue() {
			this.formValidate.value = String(this.detail[this.formValidate.type]);
		},

	},
	methods: {

		/**
         * 重置form_data
         * @return {undefined}
         */
		resetFormData() {
			this.formValidate.type = '';
			this.formValidate.value = '0';
		},

		/**
         * 确认搜索
         * @return {undefined}
         */
		confirmUpdate() {
			const param = {
				id: this.detail.id,

				type: this.formValidate.type,

				value: this.formValidate.value,
			};

			this.resetFormData();

			this.$emit('update', param);
		},

	},

};

</script>
